package 小测试;

/**
 * Created by Administrator on 2017/8/5.
 */
public class This关键字测试 {
    public static void main(String [] args){
        System.out.println(new B().getValue());
    }
    static class A{
        protected int value;
        public A(int v) {
            setValue(v);
        }
        public void setValue(int value){
            this.value = value;
        }
        public int getValue(){
            try{
                value++;
                return value;
            } catch(Exception e){
                System.out.println(e.toString());
            } finally {
                this.setValue(value);
                System.out.println(value);
            }
            return value;
        }
    }
    static class B extends A{
        //注意：在执行B的构造方法时，即使跳转到A类，A类中的this也是指B类
        public B() {
            super(5);
            setValue(getValue() - 3);//不写，都默认是this。如：this.setValue(this.getValue() - 3);
        }
        public void setValue(int value){
            super.setValue(2 * value);
        }
    }
}
